#include "ai.h"
#include <windows.h>

char buffer[1024];

#ifndef WIN32
#include "..\data\ChatRules.inl"
#endif

int main(int argc, char * argv[])
{
#ifdef WIN32
	AIContext *ctx = aiCreateContext(argv[1]);
#else
	AIContext *ctx = aiCreateContext(chatRules);
#endif
	aiSayRandomGreeting(ctx, NULL);

	while(1) {
		struct AISentence *sentence;

		UINT cp = GetConsoleCP();
		SetConsoleCP(28591); //ISO 8859-1 Latin 1; Western European (ISO)
		printf("<You>: ");
		if(!gets(buffer))
			break;
		SetConsoleCP(cp);
		
		sentence = aiCreateSentence(buffer);
		if(!sentence)
			break;

		{
			struct AIRule *rule = aiGetMatchingRule(ctx, sentence);
			if(rule)
			{
				aiExecuteRule(ctx, rule, sentence);
			}
			else
			{
				aiSayRandomFallback(ctx, sentence);
			}
		}

		aiDestroySentence(sentence);
	}

	aiDestroyContext(ctx);

    return 0;
}
